package com.geeyuu.android.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

import com.geeyuu.android.GeeConfig;
import com.geeyuu.android.GeePrefrence;
import com.geeyuu.android.R;

public class SplashActivity extends BaseActivity {

    private boolean isCompleteInit = false;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.TAG = "SplashActivity";
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_layout);
        
        final Context context = this;
        final Handler handler = new Handler();
        final Runnable runnable = new Runnable() {
            @Override
            public void run() {
                if(isCompleteInit){
                    Intent intent = new Intent();
                    if(GeePrefrence.getMyUid(SplashActivity.this) > 0){ //已经成功登录过，直接跳进主界面
                        intent.setClass(context, MainTabActivity.class);
                    }else{ //没有登录过，说明是新用户，则直接跳转到登录页面
                        intent.setClass(context, LoginActivity.class);
                    }
                    startActivity(intent);
                    finish();
                }else{
                    handler.postDelayed(this, 200);
                }
            }
        };
        handler.postDelayed(runnable, GeeConfig.splashTime);
        if(GeeConfig.initApp(getApplicationContext())){
            isCompleteInit = true;
        }
    }
    
}
